Skip to main content

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Jump Statement used in Computer Programming, C Language

After discussing about looping statements in computer programming, programmer should know about jump statements. These statements are used to jump forward/backward, on a given condition. This article will give you a brief overview in c language.

Sometimes, during the execution of a loop it may be desirable to skip execution of some statements or leave the loop when a certain condition occur. For example, during searching process, if the desired item found then there is no need to search further. In such cases, we have to terminate the loop using jump. The various jumps in loops are as follows:


Jump Statement used in Computer Programming, C Language

goto statement

goto statement is a jump statement that transfers the control of the specified statement in a program. This is an unconditional branch statement. The specified statement is identified by a symbolic name (any identifier) ending with colon ':'.
Syntax:
    goto label:
Where
  • goto – is a reserve word or keyword
  • label – is an identifier ending with colon ‘:’
Disadvantages:
  • Using goto statement in a program is an unstructured programming style.
  • The unstructured program written using goto statement are very difficult to read and understand.
  • It is also very difficult to debug the program.
Example: A C program to add all the natural numbers using goto statement.
main()
{
  int n,i,sum;
  clrscr();
  printf(“Enter the number od terms:”);
  scanf(“%d”,&n);
  sum=i=0;
  top:    sum=sum+i;
    i=i+1;
    if(i<=n) goto top;
    printf(“Sum of series = %d”,sum);
  getch();
}


Jump Statement used in Computer Programming, C Language output

Break Statement

The break statement is another jump statement which is frequently used in switch statement and loops. The break statement works as follows:
  • The 'break' statement is part of switch statement causes control to exit the switch statement. Usually, in any case, the break statement will be the last statement.
  • If break is executed in any type of loop like for, while or do-while, the control comes out of the loop and the statement following the loop will be executed. The break statement is used mainly to terminate the loop when a specific condition is reached.
Note: If ‘break’ appears in the inner loop of a nested loop, control only comes out of the inner loop.
Consider the following program segment:
    i = 1;
    for(; ; )
    {
      if(i==5) break;
      printf(“%d”,i++);
    }
In the given for loop, there is no initialization, condition and re-initialization part. Such loop is called as infinite loop. Even though it appears as an infinite loop, as the value of i reaches to 5, the control immediately comes out of the loop. When the value of i is compared with 5, the break statement is executed and the control immediately comes out of the loop.

Continue statement:

The continue statement is used only in the loops to terminate the current iteration. During execution of a loop, it may be necessary to skip a part of the loop based on some condition e.g. during processing of student records, it may be necessary to exclude student names whose marks are less than or equal to 35. In such case, a test is made to see whether the marks scored are less than or equal to 35. If so, the part of the program that processes the student details can be skipped using continue. 

But, the execution continues with next iteration of the loop. In the while statement and do-while statement, whenever a continue statement is executed, the rest of the statements within the body of the loop are skipped and the conditional expression (conditional statement) is executed. But, in for loop, the updating statement will be executed. For example, consider the statements shown below:
    for(i=1;i<=5;i++)
    {
      if(i==2) continue;
      printf(“%d”,i);
    }
Note that when i takes the value 2, the continue statement is executed and the statements following continue are skipped. The control is transferred to updating i.e. i++ statement and the execution continues from that point. The output of this program is 1 3 4 5.

Difference between break and continue statement


Difference between jump statements in computer programming

Array in Computer Programming

Comments

Popular Post

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows: Polynomial:      3x 3 -4x 2 +2x-9 Linked List: In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable. Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of