Tutorial by Examples

One of the simplest ways to control program flow is by using if selection statements. Whether a block of code is to be executed or not to be executed can be decided by this statement. The syntax for if selection statement in C could be as follows: if(cond) { statement(s); /*to be executed, o...
While if performs an action only when its condition evaluate to true, if / else allows you to specify the different actions when the condition true and when the condition is false. Example: if (a > 1) puts("a is larger than 1"); else puts("a is not larger than 1"...
switch statements are useful when you want to have your program do many different things according to the value of a particular test variable. An example usage of switch statement is like this: int a = 1; switch (a) { case 1: puts("a is 1"); break; case 2: puts("...
While the if ()... else statement allows to define only one (default) behaviour which occurs when the condition within the if () is not met, chaining two or more if () ... else statements allow to define a couple more behaviours before going to the last else branch acting as a "default", i...
Nested if()...else statements take more execution time (they are slower) in comparison to an if()...else ladder because the nested if()...else statements check all the inner conditional statements once the outer conditional if() statement is satisfied, whereas the if()..else ladder will stop condit...

Page 1 of 1