by Dinesh Thakur Category: Control Structures

In this example, the initial and final values of loop variable i (of type int) are 1 and 10, respectively. The increment expression, i += 1, increases the value of i by 1. Thus, i assume values 1, 2, 3, 4 and 5.

 
by Dinesh Thakur Category: Control Structures

For loop: When it is desired to do initialization, condition check and increment/decrement in a single statement of an iterative loop, it is recommended to use 'for' loop.

 
by Dinesh Thakur Category: Control Structures

In this example, a for loop is set up with values of loop variable num from m to n. The if statement is executed for each value of num and if nums an odd number (num%2 equals 1), it is printed using the printf statement. The output of this code is given below for m= 20 and n=40.

 
by Dinesh Thakur Category: Control Structures

C has GOTO statement but one must ensure not to use too much of goto statement in their program because its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated. First let us see what the goto statement does, its syntax and functionality. The goto is a unconditional branching statement used to transfer control of the program from one statement to another.

 
by Dinesh Thakur Category: Control Structures

C has looping , in which a sequence of statements are executed until some conditions for termination of the loop are satisfied.

 
by Dinesh Thakur Category: Control Structures

The program segment given below accepts numbers from the keyboard until we enter a zero or a negative number and calculates their sum excluding the last number.

 
by Dinesh Thakur Category: Control Structures

This program segment given below uses a straight-forward approach to count the number of odd and even digits in a given integer number(num).

 
by Dinesh Thakur Category: Control Structures

The outer for loop is set up to process each number in the given range. Each number is tested within this loop using the simplified code. The execution of the break statement causes inner for loop to terminate as it is the nearest loop enclosing the break statement. If the inner for loop is completely executed, i. e., if condition d == num is true, num is printed as a prime number.

 
by Dinesh Thakur Category: Control Structures

The if statement within the body of the for loop is used to print a comma after each value of the loop variable except the last one.

Consider the code given below to print a comma-separated list of numbers from 1 to 10:

 
by Dinesh Thakur Category: Control Structures

Three positive integer numbers a, band c, such that a<b<c form a Pythagorean triplet if c2= a2 +b2 , i. e,, a, b and c form the sides of a right-angled triangle. To select the values of a and b such that a < b and a, b < max, we can use nested for loops as shown below:

 
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content