{"id":277,"date":"2017-06-12T08:36:00","date_gmt":"2017-06-12T08:36:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2017\/06\/12\/compare-c-and-scalar-programming-languages-part-1\/"},"modified":"2020-11-05T12:43:14","modified_gmt":"2020-11-05T11:43:14","slug":"compare-c-and-scalar-programming-languages-part-1","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/compare-c-and-scalar-programming-languages-part-1\/","title":{"rendered":"Compare C# and Scalar Programming Languages &#8211; Part 1"},"content":{"rendered":"<p>This is an assignment given to MSc. Students of the University of Port Harcourt as well as the Rivers State University of Science and Technology here in Nigeria.<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'trebuchet ms' , sans-serif;\"><br \/>\n<\/span><span style=\"font-family: 'trebuchet ms' , sans-serif;\">We are going to make the comparison based on the sub-topics listed below and then we would also look at the similarities and differences.<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'trebuchet ms' , sans-serif;\"><br \/>\n<\/span><span style=\"font-family: 'trebuchet ms' , sans-serif;\">Also to be examined, in the second part is Object Oriented Programming Concepts.<\/span><\/div>\n<ol style=\"font-family: 'segoe ui';\">\n<li>Background<\/li>\n<li>Assignment Statements and Expressions<\/li>\n<li>Data Types<\/li>\n<li>Relational Operators<\/li>\n<li>Conditional Control Structure<\/li>\n<li>Looping Constructs<\/li>\n<li>String Manipulation<\/li>\n<li>Functions and Procedures<\/li>\n<li>Array Declaration and Manipulation<\/li>\n<li>Lists and Pointers<\/li>\n<li>Sets<\/li>\n<li>Polymorphism<\/li>\n<li>Summary and Final Notes<\/li>\n<\/ol>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>1. Background<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">Here we would Examine the background and history of both programming languages<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Background of C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">The C# Programming Language was designed and developed by Microsoft \u00a0with the development team led by a Computer Programmer named Anders Hejlsberg. The first release of C# appeared in the year 2000 but as of then was not very stable.<\/div>\n<div style=\"font-family: 'segoe ui';\">C# is a multi-paradigm programming language. This means that the language can be has features of an Object Oriented Programming Language while at the same time can be used as a Functional or Structural Language as well as Event-Driven language.<\/div>\n<div style=\"font-family: 'segoe ui';\">The development of C# was influenced by Languages such as Java, C and C++.<\/div>\n<div style=\"font-family: 'segoe ui';\">The latest version of C# as of the time of this article is version 6 with was released in 2015.<\/div>\n<div style=\"font-family: 'segoe ui';\">C# files have the extension .cs.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Background of Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">The Scala Programming Language just like C# is also a multi-paradigm programming language and therefore exhibit features of both OOP languages and functional languages.<\/div>\n<div style=\"font-family: 'segoe ui';\">Scala was designed by a Computer Scientist named Odersky and developed by Programming Methods Lab.<\/div>\n<div style=\"font-family: 'segoe ui';\">The Scala programming language source code was designed to be compiled into Java Bytecodes and therefore can be run on a Java Virtual Machine(JVM). This is why Scala has a strong similarity with Java.<\/div>\n<div style=\"font-family: 'segoe ui';\">The first release of Scala appeared in the year 2004. Although having similarity with Java, it is influenced by such languages as Eiffel, Lisp and SmallTalk.<\/div>\n<div style=\"font-family: 'segoe ui';\">The file extension for Scala is .sc or .scala.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>2 Assignment Statement and Expressions<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">Here we would examine assignment statement in both languages and also look at code fragments that illustrate this<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Assignment Statements in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Before we discuss assignment statements in C#, it is necessary to note that \u00a0the C# language implements strong and static data types. This means that the variables must be declared before they can be assigned values.<\/div>\n<div style=\"font-family: 'segoe ui';\">Remember that in the compilation process, data types (for languages that support strong data typing) are checked during the semantic analysis phase.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">In C#, variables are declared with the syntax:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">&lt;datatype&gt; variable;<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">So if we want to declare a variable called total as integer, we would say:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">int total;<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">Don&#8217;t forget that lines of codes in C# is terminated by a semicolon(;).<\/div>\n<div style=\"font-family: 'segoe ui';\">After a variable is declared, \u00a0a value can be assigned using the assignment operator(=). The syntax is as follows:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">&lt;variable_name&gt; = &lt;value&gt;<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">This reads as, &#8220;variable_name gets value&#8221;<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">Not &#8220;variable equals value&#8221; (this is important to know!)<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">An example would be when we assign a value of 15 to a variable named sum, the assignment statement would be:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">sum = 15;<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">We can also declare a variable and assign it a value in the same line, thus:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">int sum = 15;<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Assignment Statement in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">The Scala Language has different syntax fro declaring and assigning variables. In Scala, the var keyword is used to declare a new variable. The format is:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">var MyName: String;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">This declares a variable MyName as s string type. Also note that the line is terminated with a semicolon just like in C#.<\/div>\n<div style=\"font-family: 'segoe ui';\">You can assign a value to a variable using the assignment operator (=). YOu can also declare a variable and assign a value to it in the same line. The examples below are valid assignment statements in Scala:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">var MyName: String = &#8220;The Genius&#8221;;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\"><br \/>\n<\/span><span style=\"font-family: 'courier new' , 'courier' , monospace;\">var Number : int;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">Number = 56;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">The first line declares a variable MyName as a string type and assigns it a value of &#8220;The Genius&#8221;<\/div>\n<div style=\"font-family: 'segoe ui';\">The second line declares a variable Number as integer<\/div>\n<div style=\"font-family: 'segoe ui';\">The third line, assigns a value of 56 to the Number variable<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>3. Data Types<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">Data types are part of every programming language, so we are going to examine the data types available in both C# and Scala.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Data Types in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">The data stored in the computer memory can be of different types. For example, someone&#8217;s age is stored as a numeric value and his address stored as alphanumeric characters made up of both numbers and alphabets. C# has various standard data types that are used to define the operations possible on them and the storage method for each of them.<\/div>\n<div style=\"font-family: 'segoe ui';\">Just as I mentioned before, C# supports strong data types, which means that the variables must be declared \u00a0as the appropriate type before they can be assigned a value. Let&#8217;s outline a few of the most common data types in C#.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">The table below shows the data types in C#<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"clear: both; font-family: 'segoe ui'; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/3.bp.blogspot.com\/-BfvB5uSmTX4\/WUEimQHWQPI\/AAAAAAAAAFs\/LJZvw1Bzqa429p0oGMT6yss1IYouryR7ACLcBGAs\/s1600\/Data%2Btypes%2Bin%2BC%2523.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/3.bp.blogspot.com\/-BfvB5uSmTX4\/WUEimQHWQPI\/AAAAAAAAAFs\/LJZvw1Bzqa429p0oGMT6yss1IYouryR7ACLcBGAs\/s400\/Data%2Btypes%2Bin%2BC%2523.jpg\" width=\"400\" height=\"332\" border=\"0\" data-original-height=\"440\" data-original-width=\"526\" \/><\/a><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">We also have Date data type and String data type that would be discussed under String Manipulation<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Data Types in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">The Scala Programming Language shares the same data types with Java as well as the same precision. All data types in Scala are objects as opposed to basic types. This means that you cal actually call methods on them. More of this under Functions and Procedures.<\/div>\n<div style=\"font-family: 'segoe ui';\">The most common Scala data types are given below<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<ul>\n<li>Byte: 8 bits signed value. From -128 to 127<\/li>\n<li>Short: 16 bit signed value. From -32768 to 32767<\/li>\n<li>Int: 32 bit signed value<\/li>\n<li>Long: 64 bit signed value<\/li>\n<li>Float: 32 bit<\/li>\n<li>Double: 64 bit<\/li>\n<li>Char:16 bit<\/li>\n<li>String: Sequence of chars<\/li>\n<li>Boolean: True or False value<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>4. Relational Operators<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\"><b>Relational Operators in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">These are operators that compare the value on either sides of an expression and determine the relation \u00a0between them. Below is a list of relational operators supported by C#<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>= = (Equal)<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Checks if the values of the two operands are equal. If yes, the condition evaluates to True, else False<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>!= ( Not Equal)<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Checks if the values of the two operands are equal or not equal, if the values are not equal, then the expression evaluates to true<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>&gt; (Greater Than)<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Checks if the value of the left variable is greater than that of the right, if yes, then the condition becomes True<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>&lt; (Less Than)<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Checks if the value of the left variable is less than that of the right, if yes, then the condition becomes True<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>&gt;= (Greater Than or Equal)<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Checks if the value of the left variable is greater than or equal to the value of the right operand, if yes, the condition evaluates to True<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>&lt;= (Less Than or Equal)<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Checks if the value of the left variable is less than or equal to the value of the right operand, if yes, the condition evaluates to True<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Relational Operators in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">The relational operators in Scala is exactly the same as in C#<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>5. Conditional Control Structure<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">Conditional Control Structure are programming constructs used for decision-making in a program.<\/div>\n<div style=\"font-family: 'segoe ui';\">This requires that the programmer should specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statement or statements to be executed if the condition is determined to be false.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">This is illustrated by the figure below:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"clear: both; font-family: 'segoe ui'; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/4.bp.blogspot.com\/-v5O8Zaaj9wg\/WT5pFiINMlI\/AAAAAAAAAAo\/eF6JUWgNM_sEdo2GKDZqgjMHEEE1QZYwACPcBGAYYCw\/s1600\/Control_Structures.jpeg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/4.bp.blogspot.com\/-v5O8Zaaj9wg\/WT5pFiINMlI\/AAAAAAAAAAo\/eF6JUWgNM_sEdo2GKDZqgjMHEEE1QZYwACPcBGAYYCw\/s400\/Control_Structures.jpeg\" width=\"400\" height=\"280\" border=\"0\" data-original-height=\"532\" data-original-width=\"758\" \/><\/a><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">In the flowchart, the first step in a conditional control structure is to test if a condition is true. If the condition is true, a code is executed, if false, that program continues execution in a different path.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Conditional Control Structure in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">In C#, conditional control\/decision making is achieve by the use of if\/else statement and switch statement<\/div>\n<div style=\"font-family: 'segoe ui';\"><b>if statement<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is make up of an expression that evaluates to either True or False, followed by statement to be executed when the expression is true. If the expression evaluates to true, the statement is executed, if not, the statement is skipped.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>if\/else statement<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">An if\/else statement contains an if part and an else part as well as a conditional expression that evaluates to True or False. If the expression evaluates to True, the if part is executed, if it evaluates to false, the else part is evaluated.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>nested if statement<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is a situation where an if statement is used inside another if statement.<\/div>\n<div style=\"font-family: 'segoe ui';\">The code below illustrates the format of if\/else statement in C#<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0if(conditional_expression)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">{<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \/\/code to be executed is expression is true\u00a0<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">else<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">{<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0\/\/code to be executed if expression is false<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>switch statement<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">A switch statement contains a variable that is examined and bases on the value of the variable, the program execution switches to a particular piece of code to be executed.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>nested switch statements<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is used to nest a switch statement inside another switch statement<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Conditional Control Structure in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is achieved using the following code:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">if(conditional_expression)<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \/\/Statements will execute if expression is true<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">In the above code, the statement inside the curly braces would be executed only if the conditional_expression evaluates to true. If not the code is skipped and the execution continues with the lines of code after the curly braces.<\/div>\n<div style=\"font-family: 'segoe ui';\">The program fragment below illustrates this further<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">object Example{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 def main(args: Array[String])<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 {<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 var x = 50;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 if( x &lt; 100)\u00a0<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 {<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0println(&#8220;This is the Genius&#8221;);<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 }<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">The result of the above program when run would print out &#8220;This is the Genius&#8221;. The conditional expression would evaluate to True because the variable x which have a value of 50 is less than 100<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>6. Looping Constructs<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">Looping provides a way to allow a piece of code to execute a number of times bases on a specified condition.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"clear: both; font-family: 'segoe ui'; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/2.bp.blogspot.com\/-KrqCuL_tLuA\/WT5uncrBi1I\/AAAAAAAAAA4\/6VSHu89q00gkABeBMnezzeaU5zgyUVJdQCPcBGAYYCw\/s1600\/loop%2BConstruct.jpeg\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/2.bp.blogspot.com\/-KrqCuL_tLuA\/WT5uncrBi1I\/AAAAAAAAAA4\/6VSHu89q00gkABeBMnezzeaU5zgyUVJdQCPcBGAYYCw\/s400\/loop%2BConstruct.jpeg\" width=\"400\" height=\"256\" border=\"0\" data-original-height=\"364\" data-original-width=\"568\" \/><\/a><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Looping Constructs in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">C# Programming language provides the following types of loops to handle looping requirements. So we now examine the various types of loops and their implementation in C#<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>While Loop<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the body of the loop. The syntax for the while loop is a given below:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">while (conditional_statement)<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0\/\/statements to be executed<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\"><br \/>\n<\/span><span style=\"font-family: 'courier new' , 'courier' , monospace;\"><br \/>\n<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>For Loop<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This type of loop executes a group of statements multiple times and abbreviates the code that manages the variable is a certain condition is reached based on a loop variable. The syntax for the for loop is given below:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">for(init; condition; increment)<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0\/\/Statements to be executed<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Do&#8230;While Loop<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is similar to the while loop. The difference is that this loop tests the condition at the end of the body of the loop. The format is given below.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">do<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \/\/statements to be executed<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\"><br \/>\n<\/span><span style=\"font-family: 'courier new' , 'courier' , monospace;\">} while(condition);<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Nested Loops<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is a loop inside another loop. This is shown below for the while loop:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">while (conditional_statement)\/\/outside loop<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0\u00a0<\/span><span style=\"font-family: 'courier new' , 'courier' , monospace;\">while (conditional_statement) \/\/ nested loop<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 {<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0\/\/statements to be executed<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 }<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0\/\/statements to be executed<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Looping Construct in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">This is similar to the looping constructs for C#<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>7. String Manipulation<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">A string is a sequence of one or more characters enclosed in double quotes. Examples of string are:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">&#8220;Kindson Munonye&#8221;<\/div>\n<div style=\"font-family: 'segoe ui';\">&#8220;The Tech Pro&#8221;<\/div>\n<div style=\"font-family: 'segoe ui';\">&#8220;Akokwa&#8221;<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>String Manipulation in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">C# provides a number of ways to manipulate strings. The operations that can be used for string manipulation in C# includes the following:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<ul>\n<li>Joining of two strings (called Concatenation)<\/li>\n<li>Getting the length of a string<\/li>\n<li>Getting substring from another string<\/li>\n<li>Finding the index of a string inside another string<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>String Manipulation in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">Strings in Scala are similar to strings in Java. A Scala string is an object that cannot be modified. The codes below can be used to create a string in Scala.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">var greetings = &#8220;Hello World!&#8221;;<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">var greetings : String = &#8220;Hello World!&#8221;;<\/span><\/p>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">The codes above creates a string object, and in this case, &#8220;<i>Hello World<\/i>&#8220;.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">Scala provides methods known as ancestor methods which are used to obtain information about a string. To get the length of a string (that is the number of characters in the string), we use the length() method.<\/div>\n<div style=\"font-family: 'segoe ui';\">The code fragment below shows how we can obtain the length of a string, that is the number of characters making up the string.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">object Demo<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0def main(args: Array[String])\u00a0<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0var my name = &#8220;Kindson The Tech Pro&#8221;;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0var len = m\u00e1name.length();<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0println(&#8220;The length of the string is &#8221;\u00a0+ len);<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">The output of the code would be:<\/div>\n<div style=\"font-family: 'segoe ui';\"><i>The length of the string is 20<\/i><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">Concatenation is the joining of two string to yield a larger string. The accessor function to achieve this is concat(). The code fragment below illustrates its use<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">&#8230;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">String1 = &#8220;Kindson&#8221;;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">String2 = &#8220;Munonye&#8221;;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">String3 = String1.concat(String2);<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">&#8230;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">After this codes executes, String3 would contain KindsonMunonye<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>8. Functions and Procedures<\/b><\/div>\n<hr style=\"font-family: 'segoe ui';\" \/>\n<div style=\"font-family: 'segoe ui';\">A function is a group of statements that perform a task. You can divide up you code into separate functions. This functions come together to make up the complete program.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Functions and Procedures in C#<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">A function in C# allows you to put together a piece of code and call it from other parts of your program. You may encounter a situation where you may have to repeat a piece of code fragment, in multiple parts of your program and this is where functions would be very useful. In C#, functions are basically declared like this:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">&lt;visibility&gt; &lt;return_type&gt; &lt;function_name&gt;<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">(&lt;parameters&gt;)<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0body_of_function<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">An example of a typical function is given below.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">public in Max(int a, int b)<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">{<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0if(a &gt; b)<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return a:<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0else<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return b; \u00a0 \u00a0\u00a0<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><b>Functions and Procedures in Scala<\/b><\/div>\n<div style=\"font-family: 'segoe ui';\">In Scala, there is both functions as well as methods. Methods may also be functions with a little difference. A method in Scala is part of a class that has a name, a definition and some anotations which may be optional<\/div>\n<div style=\"font-family: 'segoe ui';\">Function on the other hand, is a complete object which can be assigned to a variable. Therefore if a function is defined as a member of some class, it can be called a method of that class.<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\">To declare a function in Scala, use the syntax:<\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">def &lt;function_name&gt; ([argument_list]) : [return_type] =<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 function body<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">\u00a0 \u00a0 return [expression]<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><span style=\"font-family: 'courier new' , 'courier' , monospace;\">}<\/span><\/div>\n<div style=\"font-family: 'segoe ui';\"><\/div>\n<div style=\"font-family: 'segoe ui';\"><a href=\"https:\/\/kindsonthegenius.com\/blog\/compare-c-and-scala-programming-languages-part-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">Continue to Part 2&#8230;<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This is an assignment given to MSc. Students of the University of Port Harcourt as well as the Rivers State University of Science and Technology &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[414],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/277"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=277"}],"version-history":[{"count":4,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/277\/revisions"}],"predecessor-version":[{"id":1645,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/277\/revisions\/1645"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}