Swift: Switch and default case

This entry is part 27 of 41 in the series Swift

As in any other programming languages, the default case will be called when none of the cases are matched.

var num = 100
switch num {
case 10:
    print("=10")
case 20:
    print("=20")
case 30:
    print("=30")
case 40:
    print("=40")
default:
    print("None of the above")
}

swift

C#: Pascal and camel case format

This entry is part 15 of 71 in the series C#

In C#, there are 2 general ways to declare an identifier such as variable name or class name.

The first is the Pascal format where the we capitalize the first letter of each word in an identifier name.  These are commonly used in Class names, namespace names and function names.

Example: Hello, DisplayName, PrintOutput

Another common format is the camel case where the first letter is in lowercase.  These are commonly used for varriable names.

Example: quotient, firstName, book, camelCase

We should use more meaningful names for classes and variables.  Note that variables in C# are case sensitive.

Use Meaningful Identifiers
using System;

namespace Hello
{
    class Friend
    {
        public void displayName()
        {
            string name;

            Console.WriteLine("Hello, what is your name?");
            name = Console.ReadLine();
            Console.WriteLine("Your name is " + name);
            Console.ReadLine();
        }

        static void Main()
        {
            Friend friend = new Friend();
            friend.displayName();
        }
    }
}

hello

 

PHP: Variables are case sensitive

This entry is part 6 of 54 in the series PHP Tutorial

In PHP variables declared are case sensitive.

<?php
$myText = 'I love programming ';
$mytext = 'the most liberal programming language in the world PHP.';

echo "$myText  $mytext";
?>
Try The Code

$myText is not the same as $mytext in PHP.

Note also variable string can be declared in single quote such as ‘I love programming’. We have put 2 variables in the echo statement.

If you changed echo statement into using single quotes, it will not work in this case.  Try to stick to using double quotes in echo statement.