Ruby Course – Worldwideasy – 04

Ruby lesson 4. I will focus on Getting Control Statements (IF statement, Case Expressions, loops), Comments, and File Control. It can provide extensive knowledge.

Control Statements

A control statement is a statement that determines whether other statements are active. If a statement decides whether another statement should be executed, or one of the two statements to be executed. A loop determines the number of times another expression should be executed.

Basically have 3 control statement

  • IF
  • Switch
  • Loops

IF Statement in Ruby

If a statement is used to check the condition, it can be a condition or more. The special feature of it is that you can check any gap. The following example will make it clear to you.

ismale = false 
if ismale
   puts "you are male"
else
   puts "you are not male"
end

This Code output is you are not male.

Case Expressions

The Case Expressions is used to check several non-gap conditions. This works very fast and gets the idea below

def get_day_name(day)
day_name=" "

case day
when "mon"
day_name = "Monday"
when "tue"
day_name = "Tuesday"
when "wed"
day_name = "Wednesday"
when "tur"
day_name = "Thursday"
when "fri"
day_name = "Friday"
when "sat"
day_name = "Saturday"
when "sun"
day_name = "Sunday"
else
day_name = "Invalid"
end
return day_name
end
puts get_day_name("wed")

This code output is Wednesday.

Loops

Loops have main 3 loops in php

  • For loop
  • While loop

Now I show the First 3 loops using Code. See Below all code output is the same. output is : 1,2,3,4,5,6,7,8,9,10.

For Loop with Arry

num = [1,2,3,4,5,6,7,8,9,10]
for num in num 
puts num
end

While Loop

index = 1
while index < 8
puts index 
index + = 1
end

Ruby Comment

Comments are a special character in programming.

# single line comment
= multiline
  comment =

File Control using Ruby

Here we show you how to handle files without opening them. see below

Reading File
file.open("test.txt",r) do |tile|
puts file.read
end
Write File
File.open("employee.txt","a") do |file|
file.write ("sanka")
end
Create File
File.open ("index.html","w") do |file|
file.write("<h1>Hello</h1>")
end
Read and Write
File.open ("employee.txt","rt") do |file|
file.readline()
file.write ("overridden")
end

Class & Object

Class is collection of objects and functions. In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

This is the mining of the object and class. now we can try to add it ruby. look below example.

class Book
attr_accessor :title, :author, :pages
end

book1 = Book.new()
book1.title = "Harry Potter"
book1.auther = "JK"
book1.pages = 400
puts book1.pages

Output is 4000.

Method

See the below example. that use code reuses it easy for developing softwares.

Class
attr_accessor:name, :major, :gpa
def initialize (name,major,gpa)
@ name = name
@ major = major
@ gpa = gpa
end
end
student1 = student.new ("harry","bio","3.6")
student2 = student.new ("jhone","chem","2.1")

puts.student1.name

Output is harried.

Create a Ruby 2D Game

First, install ruby 2d gem. open cmd

gem install ruby2d

Click Here to get the Source code.

you can see the below output in-game.

Now over the Ruby basic course. you go to this link and answer the question and get a Ruby certificate. Get Certificate

Thank you for all!

More Ruby ClickHere!

See you Next Lesson Soon!

C# Course – Worldwideasy – 01

C # is a multi-purpose programming language with general-purpose, including static typing, robust typing, vocabulary scope, essential, expression, functional, generative, object-oriented, and component-oriented programming discipline.

Today we expect basic knowledge from installing c # on a computer to coding and outputting.

C #  created by Microsoft Corporation. The platform here is a common language infrastructure. It is best to use Microsoft Visual Studio as the editor. Also, software such as Resharper can be used. The main framework of C # is the .NET Framework, which makes it easy to create user interfaces. C # is a language commonly used to build Windows applications and games.

C# does not need to be specifically entered into the computer. It is obtained automatically installing visual studio..

Start C# Coding

  1. First you want Download And Install Visual Studio(Windows operating system).
  2. Open Visual Studio.
  3. Go file and New project.
  4. Select Visual C# to Console Application and ok.
  5. After you can see Default code in below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Code Here 
}
}
}

The code above must be present.

First Code in C#

Let’s see how to write code to print hello world.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.ReadLine(); 
}
}
}

Type the code above in the toolbar. Click the Start button and you will get the output on a black screen as shown below.

hee
Output

Now you can type the code and run it. Edit the code above and try again. Next, we are going to show any shape using only the code called writeline();.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("      **");
Console.WriteLine("      /|");
Console.WriteLine("     / |");
Console.WriteLine("    /  |");
Console.WriteLine("   /   |");
Console.WriteLine("  /    |");
Console.WriteLine(" /     |");
Console.WriteLine("|      |");
Console.WriteLine("|      |");
Console.WriteLine("|      |");
Console.WriteLine("|______|");
Console.ReadLine();
}
}
}

Thank you for all!

More C# ClickHere!

See you Next C# Lesson Soon!