Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ce089
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Walmes Marques Zeviani
ce089
Commits
4fc07e09
Commit
4fc07e09
authored
6 years ago
by
Walmes Marques Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Complementa revisão de programação.
parent
1544df3a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
slides/01-revis-program.Rnw
+202
-1
202 additions, 1 deletion
slides/01-revis-program.Rnw
with
202 additions
and
1 deletion
slides/01-revis-program.Rnw
+
202
−
1
View file @
4fc07e09
...
@@ -46,7 +46,7 @@ source("config/setup.R")
...
@@ -46,7 +46,7 @@ source("config/setup.R")
\end{frame}
\end{frame}
%-----------------------------------------------------------------------
%-----------------------------------------------------------------------
\begin{frame}[fragile, allowframebreaks]{Estruturas de controle}
\begin{frame}[
t,
fragile, allowframebreaks]{Estruturas de controle}
\begin{minipage}[t]{0.55\linewidth}
\begin{minipage}[t]{0.55\linewidth}
...
@@ -118,6 +118,12 @@ source("config/setup.R")
...
@@ -118,6 +118,12 @@ source("config/setup.R")
<statments if FALSE and FALSE>
<statments if FALSE and FALSE>
}
}
@
@
\begin{itemize}
\item O R não tem o contrutor \texttt{elif}.
\item Quando o código tem uma linha, não precisa de \texttt{\{\}}.
\end{itemize}
\end{minipage}
\end{minipage}
\framebreak %------------------------------
\framebreak %------------------------------
...
@@ -148,10 +154,13 @@ source("config/setup.R")
...
@@ -148,10 +154,13 @@ source("config/setup.R")
@
@
\begin{itemize}
\begin{itemize}
\item O loop é executado enquanto a condição for \texttt{TRUE}.
\item \texttt{break} e \texttt{next} podem ser usados.
\item \texttt{break} e \texttt{next} podem ser usados.
\item Cuidado com loops sem condições de parada (loops infinitos).
\item Cuidado com loops sem condições de parada (loops infinitos).
\end{itemize}
\end{itemize}
\framebreak %------------------------------
\begin{block}{Pergunta}
\begin{block}{Pergunta}
\begin{enumerate}
\begin{enumerate}
\item Quando usar \texttt{for} e \texttt{while}?
\item Quando usar \texttt{for} e \texttt{while}?
...
@@ -163,8 +172,200 @@ source("config/setup.R")
...
@@ -163,8 +172,200 @@ source("config/setup.R")
{\large Laço de repetição com condional (repeat)}
{\large Laço de repetição com condional (repeat)}
<<eval = FALSE>>=
repeat {
<statments before 1st condition>
if (<1st condition>) break
<statments before 2nd condition>
if (<2nd condition>) break
<statments after 2nd condition>
}
@
\begin{itemize}
\item O loop é executado enquanto as condiçõs forem \texttt{TRUE}.
\item \texttt{break} e \texttt{next} podem ser usados.
\item As condições podem ser várias e estar em diferentes posições
dentro do código.
\end{itemize}
\framebreak %------------------------------
\begin{block}{Pergunta}
\begin{enumerate}
\item Quando usar \texttt{while} e \texttt{repeat}?
\item Qual dos dois é mais geral?
\end{enumerate}
\end{block}
\framebreak %------------------------------
{\large Estrutura de casos (switch)}
{\large Estrutura de casos (switch)}
<<eval = FALSE>>=
switch(<element>,
<value_1> = {
<statments 1st condition>
},
<value_2>= {
<statments 2nd condition>
},
{
<statments last condition>
})
@
\begin{itemize}
\item \texttt{switch()} pode representar estruturas de \texttt{if else
if} planas.
\item A condição é sempre a de igualdade.
\item Geralmente \texttt{switch()} é usado para igualdade de valor de
\emph{strings}.
\end{itemize}
\end{frame}
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}[t, fragile, allowframebreaks]{Alguns problemas}
Qual o resultado desse código?
<<eval = FALSE>>=
x <- 7
if (x > 3) {
print("3")
if (x < 5) {
print("5")
if (x == 7) {
print("7")
}
}
}
@
\framebreak
Quais números são exibidos com a execução?
<<eval = FALSE>>=
i <- 3
while (i >= 0) {
print(i)
i <- i - 1
}
@
\framebreak
Quais números são exibidos com a execução?
<<eval = FALSE>>=
i <- 5
while (TRUE) {
print(i)
i <- i - 1
if (i <= 2) {
break
}
}
@
Como ficaria se fosse usado \texttt{repeat}.
\framebreak
Qual o valor de \texttt{j}?
<<eval = FALSE>>=
j <- 0
for (i in 1:10) {
if (j %% 3 == 0) {
j <- 1
}
j <- i
}
@
\end{frame}
%-----------------------------------------------------------------------
\begin{frame}[t, fragile, allowframebreaks]{Funções}
{\large Protótipo da função}
<<eval = FALSE>>=
<funname> <- function(<arg_1>, <arg_2>, <arg_n>) {
<statments>
return(<values>)
}
<funname>(<arg_1> = <value_1>, <arg_2> = <value_2> , <arg_n> = <value_n>)
@
\framebreak
\begin{minipage}[t]{0.47\linewidth}
{\large Exemplo: fórmula de Báskara}
\begin{equation*}
x = \dfrac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}
\end{equation*}
\end{minipage}
\hspace{1em}
\begin{minipage}[t]{0.47\linewidth}
<<results = "hold">>=
baskara <- function(a, b, c) {
stopifnot(a != 0)
delta <- b^2 - 4 * a * c
if (delta > 0) {
den <- 2 * a
sqrt_delta <- sqrt(delta)
x1 <- (-b - sqrt_delta)/den
x2 <- (-b + sqrt_delta)/den
return(c(x1, x2))
} else {
return(NULL)
}
}
baskara(-3, 2, 1)
# baskara(3, 2, 1)
# baskara(0, 2, 1)
@
\end{minipage}
\end{frame}
%-----------------------------------------------------------------------
%-----------------------------------------------------------------------
{
\usebackgroundtemplate{\includegraphics[height=\paperheight, width=\paperwidth]{../img/looking-ahead.jpg}}
% \setbeamersize{text margin left=30mm}
\begin{frame}[b]{}
\hspace*{0.5\linewidth}
\begin{minipage}[t]{0.5\linewidth}
\hi{Próximo assunto}
\begin{itemize}
\item Representação de código.
\item Práticas de implementação.
\item Programação funcional.
\end{itemize}
\hi{Semana que vem}
\begin{itemize}
\item Sabatina no Moodle.
\item Aula com outro professor (talvez).
\end{itemize}
\end{minipage}
\end{frame}
}
%-----------------------------------------------------------------------
\end{document}
\end{document}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment