• Statements

    A condition statement is like a question in programming. It helps the computer decide what to do next. For example, if you go to a store, you might ask the shopkeeper if they have what you want. The shopkeeper will answer yes or no, and that will help you decide what to do next. In programming, the computer can ask itself questions to decide what it should do next.

      • If Statements

      • Javascript

        Example of if statement in javascript.
        var x = 1;
        
        if (x > 0) {
        	console.log('variable x is greater than zero'); // variable x is greater than zero 
        }
      • Dart

        Example of if statement in dart.
        void main() {
          var x = 1;
        
          if (x > 0) {
        	print('variable x is greater than zero'); // variable x is greater than zero 
          }
        }
      • D

        Example of if statement in d.
        import std.stdio : write;
        
        void main()
        {
        	int x = 1;
        
        	if (x > 0) {
        		write("variable x is greater than zero"); // variable x is greater than zero 
        	}
        }
        
      • Php

        Example of if statement in php.
        <?php
        $x = 1;
        
        if ($x > 0) {
        	print('variable x is greater than zero'); // variable x is greater than zero 
        }
      • Python

        Example of if statement in python.
        x = 1
        
        if x > 0:
        	print('variable x is greater than zero') # variable x is greater than zero 
        
      • Go

        Example of if statement in go.
        package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	if x > 0 {
        		fmt.Println("variable x is greater than zero") // variable x is greater than zero
        	}
        }
        
      • Else Statements

      • Javascript

        Example of else statement in javascript.
        var x = 1;
        
        if (x > 0) {
        	console.log('variable x is greater than zero'); // variable x is greater than zero 
        } else {
        	console.log('else, variable x is zero or less'); // else, variable x is zero or less
        }
      • Dart

        Example of else statement in dart.
        void main() {
          var x = 1;
        
          if (x > 0) {
        	print('variable x is greater than zero'); // variable x is greater than zero 
          } else {
        	print('else, variable x is zero or less'); // else, variable x is zero or less
          }
        }
      • D

        Example of else statement in d.
        import std.stdio : write;
        
        void main()
        {
        	int x = 1;
        
        	if (x > 0) {
        		write("variable x is greater than zero"); // variable x is greater than zero 
        	} else {
        		write("else, variable x is zero or less"); // else, variable x is zero or less
        	}
        }
        
      • Php

        Example of else statement in php.
        <?php
        $x = 1;
        
        if ($x > 0) {
        	print('variable x is greater than zero'); // variable x is greater than zero 
        } else {
        	print('else, variable x is zero or less'); // else, variable x is zero or less
        }
      • Python

        Example of else statement in python.
        x = 1
        
        if x > 0:
        	print('variable x is greater than zero') # variable x is greater than zero
        else:
        	print('else, variable x is zero or less') # else, variable x is zero or less
        
      • Go

        Example of else statement in go.
        package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	if x > 0 {
        		fmt.Println("variable x is greater than zero") // variable x is greater than zero
        	} else {
        		fmt.Println("else, variable x is zero or less") // else, variable x is zero or less
        	}
        }
        
      • Else If Statements

      • Javascript

        Example of else if statement in javascript.
        var x = 1;
        
        if (x > 0) {
        	console.log('variable x is greater than zero'); // variable x is greater than zero 
        } else if (x == 0) {
        	console.log('else if, variable x is zero'); // else if, variable x is zero
        }
      • Dart

        Example of else if statement in dart.
        void main() {
          var x = 1;
        
          if (x > 0) {
        	print('variable x is greater than zero'); // variable x is greater than zero 
          } else if (x == 0) {
        	print('else if, variable x is zero'); // else if, variable x is zero
          }
        }
      • D

        Example of else if statement in d.
        import std.stdio : write;
        
        void main()
        {
        	int x = 1;
        
        	if (x > 0) {
        		write("variable x is greater than zero"); // variable x is greater than zero 
        	} else if (x == 0) {
        		write("else if, variable x is zero"); // else if, variable x is zero
        	}
        }
        
      • Php

        Example of else if statement in php.
        <?php
        $x = 1;
        
        if ($x > 0) {
        	print('variable x is greater than zero'); // variable x is greater than zero 
        } elseif ($x == 0) {
        	print('else if, variable x is zero'); // else if, variable x is zero
        }
      • Python

        Example of else if statement in python.
        x = 1
        
        if x > 0:
        	print('variable x is greater than zero') # variable x is greater than zero 
        elif x == 0:
        	print('else if, variable x is zero') # else if, variable x is zero
        
      • Go

        Example of else if statement in go.
        package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	if x > 0 {
        		fmt.Println("variable x is greater than zero") // variable x is greater than zero
        	} else if x == 0 {
        		fmt.Println("") // else if, variable x is zero
        	}
        }
        
      • Switch Statements

      • Javascript

        Example of switch statement in javascript.
        var x = 1;
        
        var result = '';
        switch (x) {
        	case 0:
        		result = 'variable x is integer zero';
        		break;
        	case 1:
        		result = 'variable x is integer one';
        		break;
        	default:
        		result = 'variable x is anything else';
        }
        
        console.log(result); // variable x is integer one
      • Dart

        Example of switch statement in dart.
        void main() {
          var x = 1;
        
          var result = '';
          switch (x) {
        	case 0:
        	  result = 'variable x is integer zero';
        	  break;
        	case 1:
        	  result = 'variable x is integer one';
        	  break;
        	default:
        	  result = 'variable x is anything else';
          }
        
          print(result); // variable x is integer one
        }
        
      • D

        Example of switch statement in d.
        import std.stdio : write;
        import std.string;
        
        void main()
        {
        	int x = 1;
        
        	string result;
        	switch (x) {
        		case 0:
        			result = "variable x is integer zero";
        			break;
        		case 1:
        			result = "variable x is integer one";
        			break;
        		default:
        			result = "variable x is anything else";
        	}
        
        	write(result); // variable x is integer one
        }
        
      • Php

        Example of switch statement in php.
        <?php
        $x = 1;
        
        $result = '';
        switch ($x) {
        	case 0:
        		$result = 'variable x is integer zero';
        		break;
        	case 1:
        		$result = 'variable x is integer one';
        		break;
        	default:
        		$result = 'variable x is anything else';
        }
        
        print($result); // variable x is integer one
      • Python

        Example of switch statement in python.
        x = 1
        
        result = ''
        match x:
        	case 0:
        		result = 'variable x is integer zero'
        
        	case 1:
        		result = 'variable x is integer one'
        
        	case _:
        		result = 'variable x is anything else'
        
        print(result)  # variable x is integer one
        
      • Go

        Example of switch statement in go.
        package main
        
        import "fmt"
        
        func main() {
        	var x int = 1
        
        	var result string
        	switch x {
        	case 0:
        		result = "variable x is integer zero"
        
        	case 1:
        		result = "variable x is integer one"
        
        	default:
        		result = "variable x is anything else"
        	}
        
        	fmt.Println(result) // variable x is integer one
        }