C Language – “While” cycle and “IF” education

C Language
C Language

The while statement is composed of:

i = 0;

while (condition type i <10) {

here we will write the repetition that must be done 10 times

i = i + 1;

}

 

C Language

 

As you have seen, he repeated the operation 10 times.

Remember to increase the counter variable because if you do not, your cycle will go into infinite LOOP.

 

Stay Tuned! 

 

 The “IF” instruction

The “if” instruction is used to make comparisons or comparisons, the word “if” translated into Italian indicates “se”. So think of Italian, to make a comparison of the type if 5> 3 then do something else do another.

 

I made the example with numbers 5 and 3 but we can do it with a comparison of variable names.

 

The if statement is as follows:

 

if(type condition 5>3){

 

here we will write what our program should do if 5 and greater than 3

 

} else(translated into Italian altrimenti){

 

If the 5 and the minor respect the comparison with the second number then it will do another thing

 

}

 

I will post you a picture where I have already assigned the values ​​in the code, I remind you that you can assign them through the “scanf()” function before using the “if”.

 

C Language

 

WHILE cycle

 

The “while” loop is used to do a repetition of things, the word “while” translated into Italian indicates “mentre”. For the while loop, most of the time, you need a sentinel variable (which I’ll mention again) or a counter

 

The counter is a simple variable (usually the names of the counters are i, j, ..) placed equal to 0, where at each end cycle is increased

 

The while statement is composed of:

i = 0;

while (condition type i <10) {

here we will write the repetition that must be done 10 times

i = i + 1;

}

 

C Language

 

As you have seen, he repeated the operation 10 times.

Remember to increase the counter variable because if you do not, your cycle will go into infinite LOOP.

 

Stay Tuned! 

Giuseppe

Salve, sono un ragazzo di 25 anni, iscritto alla facoltà di informatica, appassionato di programmazione e delle nuove news tecnologiche in ambito informatico.

Related Posts

This site uses Akismet to reduce spam. Learn how your comment data is processed.