How to interrupt in Visualg?

Asked

Viewed 1,169 times

-1

Good evening, everyone. How do I interrupt a command in visualG?

What has been requested:

Write an algorithm that writes a sentence on the screen until the letter "F" is typed (without quotation marks). The phrase is as follows: The message will be stopped when the "F" key is pressed.

What I did:

Var
// Seção de Declarações das variáveis 

x,f: caracter

Inicio
// Seção de Comandos, procedimento, funções, operadores, etc... 

escreval ("A mensagem será interrompida quando a tecla F for pressionada.")
leia (x)
escreval ("Pressione a letra F para interromper a mensagem.")
leia (f)

Fimalgoritmo
  • Toguchi, equally like your other question, if you don’t develop a Minimum, Complete and Verifiable Example that demonstrates the problem that is going through use question will be CLOSED, edit your question and put an excerpt from your code.

  • I’ll be editing the question now.

1 answer

2


Use the structure enquanto... faca

Your code will look like this:

var
continuar: caracter

inicio

// Seção de Comandos, procedimento, funções, operadores, etc...
continuar:="a"
enquanto continuar <> "f" faca
escreval ("A mensagem será interrompida quando a tecla F for pressionada.")
leia (continuar)
fimenquanto
escreval ("A letra F foi pressionada")

fimalgoritmo

Like good programming practices I advise to name the variables correctly, ie, avoid use variable x or variable f

I recommend reading: VISUALG HANDBOOK

  • Thank you very much, Luiz Augusto. And thanks for the material, it will be of great help.

  • @Toguchi tour and see the best way to thank

Browser other questions tagged

You are not signed in. Login or sign up in order to post.