C language instructions

C

1. Conditional instructions
If-else
if else is the simplest conditional statement. It can be used in several forms. The statement evaluates the expression and executes the instructions between the braces only if the result is nonzero. Together with else, for the result n is executed with the instruction set situated after else.

switch
Switch is an instruction designed to simplify conditional structures with multiple conditions.
switch (expression) {
  case constant1:
    // instructions1
  case constant2:
    // instructions2
  …
  default:
    // instructions

The expression value is evaluated to an entire type; then this value is compared to each constant; the instruction block of the value found is run. If the number is not equal to any of the constants, the block is executed by default. After executing the last instruction in a block set, the execution does not continue after the block switch, but at the beginning of the next block constant or default. To exit the switch block, use the break statement.

2. Repeat instructions
while
while executes an instruction block as long as a certain condition is true. The general form of a while cycle is:
while (expression) {
  // instructions

While expression has a nonzero value, the instructions in the block after while are executed. The expression is reevaluated after each cycle. Such a cycle can be executed once, several times or never, depending on the value at which the expression is valued.

to … while
until … while is a repetitive statement similar to the previous one, the only difference being that the expression is evaluated after executing the instructions, not before.

for
for is a simpler way to write a while with an initial expression and incremental expression. Its shape is:
for (expression1; expression2; expression3) {
// instructions
For the for statement, any of the three phrases may be missing. The lack of conditional expression is equivalent to an infinite loop. The lack of conditional expression is equivalent to an infinite loop, such as: for (;;) {
  / * the instructions here are in an infinite loop * /
}

3. Special instructions
break
break, in addition to the use described in the switch statement, can be used to force you out of a repetition instruction.
continue-for (i = 0; i <10;) {
  if (i == 0) {
    continue;
  }
  i ++;
}

Continue forces the termination of the current loop iteration and move to the next iteration. For the for statement, this involves executing the incrementation statement; then the continuity of the loop is evaluated.

return
return is the instruction to terminate the current function. It can be called in the return form; for functions returning void and return result; for functions that return a value.

goto
goto is a jump instruction for execution. The instruction receives a label as a parameter; the following statement executed after goto is the one from the given tag.
int main ()
  goto et;
  printf (“This does not appear in execution \ n”);
 et:
  printf (“This appears when running \ n”);
  return 0;
In most cases, the use of the goto instruction is not recommended and can be avoided using other control instructions and functions. Programs that use this instruction to skip between remote code sequences are difficult to troubleshoot and analyze.

Recent Posts

Archives

Categories