Студопедия

Главная страница Случайная страница

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Concatenation






Concatenation is the joining together of pieces of text. In RFO Basic, you can concatenate text using the " +" symbol:

mystring$ = " Hello " + " World" + "! " print mystring$

Concatenation is particularly useful when combining static text with data stored in variables or returned by functions. You will use code similar to the following in virtually every program you write:

name$ = input " What is your name? " message$ = " Good to meet you " + name$ + "! " popup message$, 0, 0, 1

Since you can't code an unkown user's name into your program, you must use a variable, and concatenate that text with other static (unchanging) text whenever you want to refer to the user's name in your program.

To concatenate text strings on multiple lines, use the tilde character (~):

print " all this text appears on " + ~ " one line."

The " time" function sets all the following return variables to the current year, month, day, hour, minute, and second. Here's a nicely formatted concatened string that displays the current date and time:

time y$, m$, d$, h$, n$, s$ mytime$ = " The current date is " m$ + " -" d$ + " -" + y$ + ~ ", and the time is " + h$, ": ", n$, ": " s$ popup mytime$, 0, 0, 1

Again, since a programmer can't write the user's arbitrary current time into the code, variables and concatenation must be used to retrieve the current time, and refer to it by dynamically generated text.

Some Basic Text Formatting Guidelines

You can include quotes inside strings by prefacing them with the backslash character (\):

popup " \" quoted text\" ", 0, 0, 1

Multi-line text uses " \n" to represent a carriage return:

lines = " Line 1\nLine 2\nLine 3" print lines

Conditions

Conditions are used to manage program flow... to make " decisions" in your program. They are among the most important concepts in all types of programming.

If

The most basic conditional evaluation is " if":

if (this expression is true) then do this block of codeendif! parentheses are NOT required

Math operators are typically used to perform conditional evaluations: = < > < > (equal, less-than, greater-than, not-equal):

time y$, m$, d$, h$, n$, s$ h = val(h$) % the val() function converts text data to a number. % the variable " h" now stores that number. if h > 12 then % if the hour value is later than 12 o'clock, then... print " It's after noon." endif

The above code could also be written as follows. The hour text is converted to a number, inline:

time y$, m$, d$, h$, n$, s$if val(h$) > 12 then print " It's after noon." endif

Поделиться с друзьями:

mylektsii.su - Мои Лекции - 2015-2024 год. (0.006 сек.)Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав Пожаловаться на материал