Professional Documents
Culture Documents
201 Assignment 0
201 Assignment 0
i)A variable name can consist of capital letters from A-Z, lowercase letters a-z, digits and special
characters such as underscore and sign.
ii)The first character cannot be a digit.
iii)Blank spaces cannot be used in variable names.
iv)Java keywords cannot be used as variable names.
v)Variable names are case sensitive.
Vi)There is no limit on length of variable but by conversion, it should be between 5-15
characters.
vii)Variable names should always exist at the left hand side of the assignment operator.
b) JAVASCRIPT
i)The first letter of a variable must be a letter or underscore.
ii)The wrest of the variable names can include any letter, number or underscore. You cannot use
any other characters such as spaces, symbols and punctuation marks.
iii)Variable names are case sensitive.
iv)There is no limit to variable length.
v)Reserved words cannot be used as variable names.
c)PYTHON
d)PHP
i)A variable name cannot start with a number.
ii)Variable names are case sensitive.
iii)Do not use pre- defined constant names, such as PHP_VERSION, PHP_OS etc.
iv)Do not use reserved keywords as variables.
v)All variables begin with a dollar sign.
e)C#
i)A variable name can consist of capital letters, lower case letters, digits and special characters
such as underscore and dollar sign.
ii)The first character cannot be a digit.
iii)Variable names are case sensitive.
iv)Keywords cannot be used as variable names.
b)Loosely Typed
i)PHP
II)JavaScript
3a)Java
i)WHILE LOOP
example:
while (i >= 10) {
System.out.println(i);
}
iii)FOR LOOP
example:
for(int I =1; I < = 10, i++) {
System.out.println(i);
}
b)JAVASCRIPT
i)FOR LOOP
example:
for(let I =0; I <= 10, i++) {
Console.log(i);
}
ii)WHILE LOOP
example:
let count = o;
while(count < 5) {
count ++;
Console,log(count);
}
c)PHP
l)WHILE LOOP
example:
$i = 1;
While($i <= 5){
Echo($i);
$i++
}
ii)FOR LOOP
for($i = 0; $i < 10, $i++) {
echo($i);
}
d)PYTHON
i)FOR LOOP
example:
numbers = [1,2,3,4]
for x in numbers:
if(x % 2 == 0):
print(x*x)
ii)WHILE LOOP
example:
n=5
while n > o:
n=n–1
if n =2:
break
print(n)
4a) JAVA
I)IF STATEMENT
Example:
Int user = 17;
If(user < = 18) {
System.out.println(“the user is 18 years old or younger”)
}
iii)SWITCH STATEMENT
example:
switch(weekday) {
case1:
System.out.println(“Sunday”)
Break;
Case2:
System.out.println(“Monday”)
Break;
Case 3:
System.out.println(“Tuesday”)
Break;
Default:
System.out.println(“Wednesday”)
}
b)PYTHON
i)IF STATEMENT
example:
I = 23
if I %2 == 0:
print(“this is the if block”)
c)JAVASCRIPT
I)IF STATEMENT
Example:
If (day === 3) {
Console.log(“the day is Wednesday”);
}
iii)SWITCH STATEMENT
example:
switch(animal) {
case “kangaroo”:
Console.log(“usuall found in Australia”);
Break;
Case “Lions”:
Console.log(“More in Africa”);
Break;
Default:
Console.log(“the wrest are found everywhere”)
}
d)C#
i) IF STATEMENT
example:
if(I > 2) {
Console.writeline(“Change please”);
}
Else if(I < 2) {
Console.Writeline(“You can chose to change or not”);
)
Else (
Console.Writeline(“Change please”)
}
ii)SWITCH STATEMENT
example:
switch(animal) {
case “kangaroo”:
Console.writeline(“Usually found in Australia”);
break;
Case “Lion”:
Console.writeline(“Found mostly in Africa”);
Break;
Default:
Console.writeline(“the wrest can be found mostly anywhere around the world”);
}
e) PHP
i) IF STATEMENTS
example:
$name = “Eric”
If ($name == ” Mike”) {
echo “name is mike”;
}
Else if($name ==”Eric”) {
Echo “name is Eric”
}
Else {
Echo “ name is $name”;
}
ii)SWITCH STATEMENT
example:
switch ($country) {
case “USA”:
echo “you are in usa”;
break;
case “Japan”:
echo “you are in Japan”;
break;
default:
echo “I do not know your location”
}