The differences between languages…

I’ve been learning how a few different languages can do the same task, so decided to put up the examples below.

#!/usr/bin/python

number = 5
counter = 1
while (counter <=10):
    if counter < number:
        print (counter, ' is less than ', number)
    elif counter == number:
        print (counter, ' equals ', number)
    else:
        print (counter, ' is greater than ', number)
    counter = counter + 1
Code language: Python (python)
#powershell

$numValue = @(1..10)
$counter = 0

while ($counter -lt $numValue.length){
if ($numValue[$counter] -lt 5){
    write-host "Less than`n"
}
elseif ($numValue[$counter] -eq 5) {
    write-host "Equal`n"
}
else {
    write-host "Greater than`n"
}
$counter += 1
}Code language: PowerShell (powershell)
//C++
#include <iostream>
using namespace std;

int main()
{
    int counter = 1;
    while (counter <= 10) {
        if (counter > 5) { cout << "Greater than\n"; }
        else if (counter == 5) { cout << "Equal\n"; }
        else { cout << "Less than\n"; }
        counter++;
    }
    system("pause>0");
}

Code language: C++ (cpp)

Leave a Comment

3 × three =