Var Name =Console . ReadLine();

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Execute Blocks of Code Multiple Times Telerik Software Academy C# Fundamentals – Part 1.
Computer Programming Lab 8.
פתרון בוחן הכיתה. שאלה #1 Module Module1 Sub Main() Dim x, z As Integer x = Console.ReadLine() z = Console.ReadLine() If (x = 0) Then Console.WriteLine("Error")
Implementing Control Logic in C# Svetlin Nakov Telerik Corporation
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
BIM313 – Advanced Programming Techniques C# Basics 1.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
Data Types, Operators, Expressions, Statements, Console I/O, Loops, Arrays, Methods Svetlin Nakov Telerik Corporation
Introduction to C# Programming ณภัทร สักทอง Application Program Development.
INTEL ULTIMATE ENGINEERING EXPERIENCE BUILD AN APP.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
BIM313 – Advanced Programming Techniques Flow Control 1.
Iteration (Loop) partI Thanachat Thanomkulabut. Consider the following program! using System; Namespace SimPleExample { class SimPleC { class SimPleC.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Conditional Statements Implementing Control-Flow Logic in C# SoftUni Team Technical Trainers Software University
Loops Repeating Code Multiple Times SoftUni Team Technical Trainers Software University
1 Advanced Programming IF. 2 Control Structures Program of control –Program performs one statement then goes to next line Sequential execution –Different.
3 C# Control Statements Dr. John P. Abraham Professor UTPA.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
C# Basic Concept Thanachat Thanomkulabut. Naming Rules  Letters, digits and underscores(_)  First character  letter or _  Up to 63 characters long.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
CIS 3301 C# Lesson 3 Control Statements - Selection.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
Chapter One Lesson Three DATA TYPES ©
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
Lecture 2 Review of 1301 and C# Richard Gesick. Common data types int, long, double, float, char, bool, string.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Lecture 2 Computational Constructs Variables & Expressions Boolean Logic Conditionals: if & switch Branching & Looping Data Types & Type Conversion Structs,
1 nd Semester Module6 Review Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
התוכנית: using System; using System.Collections.Generic;
using System; namespace Demo01 { class Program
Repetition (While-Loop) version]
Introduction to programming in java
Compiler Design First Lecture.
Thanachat Thanomkulabut
Objectives Explain selection constructs Describe loop constructs
Functions Used to write code only once Can use parameters.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
null, true, and false are also reserved.
The University of Texas – Pan American
Variables, Loops, Decision Statements, etc
An Introduction to Java – Part I, language basics
ניתוח מערכות מידע תכנות ב C#
Exception Handling CSCI293 - C# October 3, 2005.
عرض اجمالي المهام الشرطية في سي شارب (الأمر if)
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
C# Programming.
Do … Loop Until (condition is true)
Module5 Looping Techniques: Part 2
Module5 Looping Techniques: Part 2
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
class PrintOnetoTen { public static void main(String args[]) {
Lecture 1 Review of 1301/1321 CSE /26/2018.
Module 3 Selection Structures 4/3/2019 CSE 1321 Module 3.
CSE Module 1 A Programming Primer
C# Programming: From Problem Analysis to Program Design
Module 4 Loops and Repetition 4/15/2019 CSE 1321 Module 4.
Repetition Statements
Introduction to C#.net PROF. S. LAKSHMANAN,
Presentation transcript:

Var Name =Console . ReadLine(); Reading Var Name =Console . ReadLine(); EX: static void Main(string[] args) { string x; x = Console.ReadLine(); Console.WriteLine("you entered : {0}", x); }

Integer Var =Type.Parse (String Var); EX: static void Main(string[] args) { string x; int y; x = Console.ReadLine(); y = int.Parse(x); Console.WriteLine("Square Number :{0}",y*y ); }

Use Convert static void Main(string[] args) { string x; int y; x = Console.ReadLine(); y = Convert.ToInt16(x ); Console.WriteLine("Square Number :{0}",y*y ); }

Or static void Main(string[] args) { int y; y =convert.ToInt16(Console.ReadLine()); Console.WriteLine("Square Number :{0}",y*y ); }

Control Statement 1.1. IF Statement: if (<test>) 1. Selection Statement: 1.1. IF Statement: if (<test>) <code executed if <test> is true>;

Or if (<test>) <code executed if <test> is true>; else <code executed if <test> is false>;

Or if (<test>) { <code executed if <test> is true>; } else <code executed if <test> is false>;

Ex: static void Main(string[] args) { string resultstring; int myinteger; myinteger = Convert.ToInt16(Console.ReadLine()); if (myinteger < 10) resultstring = "less than 10"; else resultstring = "greater than or equal to 10"; Console.WriteLine(resultstring); }

Ex: static void Main(string[] args) { string comparison; Console.WriteLine("enter a number:"); double var1 = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("enter another number:"); double var2 = Convert.ToDouble(Console.ReadLine()); if (var1 < var2) comparison = "less than"; else if (var1 == var2) comparison = "equal to"; comparison = "greater than"; } Console.WriteLine("the first number is {0} the second number.", comparison);

Ex: static void Main(string[] args) { Console.Write("Enter Any Character:"); char c = char.Parse(Console.ReadLine()); if (char.IsUpper(c)) Console.WriteLine("the character is upper case"); else if (char.IsLower(c)) Console.WriteLine("the character is lower case"); else if (char.IsDigit(c)) Console.WriteLine("the character is number"); else Console.WriteLine("the character is not alphanumeric"); }

1.2. The Switch Statement: Switch (<testVar>) { Case <comparisonVa1>; < code to execute if <testVar>==<comparisonVa1> > break; Case <comparisonVa2>; < code to execute if <testVar>==<comparisonVa2> > …… Case <comparisonVaN>; < code to execute if <testVar>==<comparisonVaN> > default: < code to execute if <testVar> != <comparisonVas> > }

Ex: static void Main(string[] args) { Console.Write("please Enter your Selection 1,2 or 3 :"); int x = int.Parse(Console.ReadLine()); switch (x) case 1: Console.WriteLine("your choose 1."); break; case 2: Console.WriteLine("your choose 2."); case 3: Console.WriteLine("your choose 3."); default: Console.WriteLine("Error:?: please choose 1 or 2 or 3 ."); }

Ex: static void Main(string[] args) { const string myname = "ahmad"; const string fathername = "omar"; const string mothername = "huda"; string name; Console.WriteLine("what is your name?"); name = Console.ReadLine(); switch (name.ToLower()) case myname: Console.WriteLine("you have the same name as me:"); break; case fathername: Console.WriteLine("you have the same name as my father:"); case mothername: Console.WriteLine("you have the same name as my mother:"); } Console.WriteLine("Hello {0} :", name);

2. Loops: 2.1. Do-While loop { <code to be looped> } while (<test>); Ex: static void Main(string[] args) { int i=1; do Console.WriteLine("{0}", i++); } while (i <= 10); }

2.2. While loop While (<test>) { <code to be looped> } Ex: static void Main(string[] args) { int i=1; while (i <= 10) Console.WriteLine("{0}", i++); }

2.3.For loops for (<initialization>; <condition>; <operation>) { <code of loop> } Ex: static void Main(string[] args) { int i=1; for (i = 1; i <= 10; i++) Console.WriteLine("{0}", i); }

اكتب برنامج لطباعة الاعداد من 1 الى 100 كل خمس ارقام باستخدام while H.W. اكتب برنامج لطباعة الاعداد من 1 الى 100 كل خمس ارقام باستخدام while

Interrupting loops: break Ex: static void Main(string[] args) { int i = 0; while (i <= 100 ) if (i == 6) break; Console.WriteLine("{0}", i++); }

continue static void Main(string[] args) { int i ; for (i = 1; i <= 10; i++) if ((i % 6) == 0) continue; Console.WriteLine(i); }

1 2 3 4 5 7 8 9 10

goto static void Main(string[] args) { int i =1; while ( i <= 10 ) if (i == 6) goto exitpoint; Console.WriteLine("{0}",i++); } Console.WriteLine("this code will never be reached."); exitpoint: Console.WriteLine("this code is run when loop is exited by goto.");